home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / XLIBP202.ZIP / XLIB2.DOC < prev    next >
Text File  |  1995-01-26  |  40KB  |  938 lines

  1. ╔═══════════════════════════════════════════════════════════════════════════╗
  2. ║                                                                           ║
  3. ║        XLIB v2.0 - Graphics Library for Borland/Turbo Pascal 7.0          ║
  4. ║                                                                           ║
  5. ║               Tristan Tarrant - tristant@cogs.susx.ac.uk                  ║
  6. ║                                                                           ║
  7. ╠═══════════════════════════════════════════════════════════════════════════╣
  8. ║                                                                           ║
  9. ║                                 Credits                                   ║
  10. ║                                                                           ║
  11. ║                             Themie Gouthas                                ║
  12. ║                                                                           ║
  13. ║                            Matthew MacKenzie                              ║
  14. ║                                                                           ║
  15. ║                             Tore Bastiansen                               ║
  16. ║                                                                           ║
  17. ║                                 Andy Tam                                  ║
  18. ║                                                                           ║
  19. ║                               Douglas Webb                                ║
  20. ║                                                                           ║
  21. ║                              John  Schlagel                               ║
  22. ║                                                                           ║
  23. ╠═══════════════════════════════════════════════════════════════════════════╣
  24. ║                                                                           ║
  25. ║           I informally reserve all rights to the code in XLIB             ║
  26. ║       Rights to contributed code is also assumed to be reserved by        ║
  27. ║                          the original authors.                            ║
  28. ║                                                                           ║
  29. ╚═══════════════════════════════════════════════════════════════════════════╝
  30.  
  31. ╔═══════════════════════════════════════════════════════════════════════════╗
  32. ║ DISCLAIMER                                                                ║
  33. ╚═══════════════════════════════════════════════════════════════════════════╝
  34.  
  35.     This library is distributed AS IS. The author/s specifically disclaim any
  36.     responsibility for any loss of profit or any incidental, consequential or
  37.     other damages.
  38.  
  39. ╔═══════════════════════════════════════════════════════════════════════════╗
  40. ║ INTRODUCTION                                                              ║
  41. ╚═══════════════════════════════════════════════════════════════════════════╝
  42.  
  43.     XLIB is a "user supported freeware" graphics library specifically designed
  44.     with game programming in mind.
  45.  
  46.     It has been placed in the public domain for the benefit of all, and
  47.     represents *MANY* hours of work so it is requested that all users comply
  48.     with the the wishes of the author/s as specified in the individual modules
  49.     and:
  50.     a) To leave the code in the public domain
  51.     b) Not distribute any modified or incomplete versions of this library
  52.  
  53.     New contribution and comments are welcome and hopefully there will be more
  54.     releases as the code evolves.
  55.  
  56.     Finally, do not trust this excuse for a manual if in doubt, as this code has
  57.     undergone several revisions. The place to get the answers is in the code
  58.     itself.
  59.  
  60. ╔═══════════════════════════════════════════════════════════════════════════╗
  61. ║ REQUIREMENTS                                                              ║
  62. ╚═══════════════════════════════════════════════════════════════════════════╝
  63.  
  64.     Minimum requirements
  65.     386 processor,
  66.     VGA,
  67.     Borland/Turbo Pascal v7.0
  68.  
  69. ╔═══════════════════════════════════════════════════════════════════════════╗
  70. ║ GENERAL FEATURES                                                          ║
  71. ╚═══════════════════════════════════════════════════════════════════════════╝
  72.  
  73.     Support for a number of 256 colour tweaked graphics mode resolutions :
  74.  
  75.         320x200 320x240 360x200 360x240 376x282 320x400 320x480 360x400 360x480
  76.         360x360 376x308 376x564 256x200 256x240 256x224 256x256 360x270 400x300
  77.  
  78.     Please note that some of these resolutions best suit monitors with
  79.     adjustable vertical height.
  80.  
  81.     Virtual screens larger than the physical screen (memory permitting) that
  82.     can be panned at pixel resolution in all directions
  83.  
  84.     A split screen capability
  85.  
  86.     Text functions supporting 8x8 and 8x14 ROM fonts and user defined fonts
  87.  
  88.     Support for page flipping
  89.  
  90.     Graphics primitives such as line and rectangle drawing functions and
  91.     of course bit block manipulation functions
  92.  
  93.     Virtual VSync Handler
  94.     
  95.     Compression and archiving
  96.  
  97.     GIF/BMP loading and saving
  98.  
  99. ╔═══════════════════════════════════════════════════════════════════════════╗
  100. ║ BUILDING THE LIBRARIES                                                    ║
  101. ╚═══════════════════════════════════════════════════════════════════════════╝
  102.  
  103.     To compile XLIB use the provided makefile. Just put all of the XLIB files
  104.     in the same directory and type MAKE at the DOS prompt. This will build all
  105.     the libraries and examples. If Borland Pascal isn't in your path just edit
  106.     the makefile where indicated. BP 7.0 and TASM are required to compile the
  107.     libraries.
  108.     If you want to make units with full debug information, compile with
  109.     MAKE -DDEBUG
  110.     To make the DPMI versions of the units, compile with
  111.     MAKE -DDPMI
  112.     To make the help (XLIB2.TPH) file you need ScanHelp. I used version 3.26.
  113.     MAKE HELP
  114.  
  115. ╔═══════════════════════════════════════════════════════════════════════════╗
  116. ║ USING THE LIBARY WITH YOUR PROGRAMS                                       ║
  117. ╚═══════════════════════════════════════════════════════════════════════════╝
  118.  
  119.     Using the XLIB library in your programs is simple. Just include the XLIB
  120.     units in the uses statement at the beginning of your program which will make
  121.     all the procedures and functions composing the XLIB library available.
  122.  
  123. ╔═══════════════════════════════════════════════════════════════════════════╗
  124. ║ GLOBAL CONSTANTS, VARIABLES AND TYPES                                     ║
  125. ╚═══════════════════════════════════════════════════════════════════════════╝
  126.  
  127. Type
  128.     Vertex = record
  129.         x, y : word;
  130.     end;              - Vertex record used for xpolygon.
  131.  
  132.     VBMInfoStruc = record
  133.         Size, ImageWidth, ImageHeight : word;
  134.     end;              - Video Bitmap Structure
  135.  
  136.     VBMAlignmentStruc = record
  137.         ImagePtr, MaskPtr : word;
  138.     end;              - Video Bitmap Structure to data in VRAM
  139.  
  140.     AlignmentHeader = record
  141.         size, ImageWidth, ImageHeight : word;
  142.         alignments : array[0..3] of
  143.         record
  144.              ImagePtr, MaskPtr : word;
  145.         end;
  146.     end;              - Video Bitmap VRAM stuff
  147.  
  148.     LBMHeader = record
  149.         width, height : byte;
  150.     end;              - Linear/Planar Bitmap header
  151.  
  152.     PAlignmentHeader = ^AlignmentHeader;
  153.                                         - Pointer to VBM VRAM info
  154.  
  155. Const
  156.     XMode320x200  = 0;       320x200x256 colors - 4.0+ pages
  157.     XMode320x240  = 1;       320x240x256 colors - 3.4+ pages - Square Pixels
  158.     XMode360x200  = 2;       360x200x256 colors - 3.6+ pages
  159.     XMode360x240  = 3;       360x240x256 colors - 3.0+ pages
  160.     XMode376x282  = 4;       376x282x256 colors - 2.4+ pages - Square Pixels
  161.     XMode320x400  = 5;       320x400x256 colors - 2.0+ pages
  162.     XMode320x480  = 6;       320x480x256 colors - 1.7+ pages
  163.     XMode360x400  = 7;       360x400x256 colors - 1.8+ pages
  164.     XMode360x480  = 8;       360x480x256 colors - 1.5+ pages
  165.     XMode360x360  = 9;       360x360x256 colors - 2.0+ pages
  166.     XMode376x308  = 10;      376x308x256 colors - 2.2+ pages
  167.     XMode376x564  = 11;      376x564x256 colors - 1.2+ pages
  168.     XMode256x200  = 12;      256x200x256 colors - 5.1+ pages
  169.     XMode256x240  = 13;      256x240x256 colors - 4.2+ pages
  170.     XMode256x224  = 14;      256x224x256 colors - 4.5+ pages
  171.     XMode256x256  = 15;      256x256x256 colors - 4.0  pages
  172.     XMode360x270  = 16;      360x270x256 colors - 2.6+ pages - Square Pixels
  173.     XMode400x300  = 17;      400x300x256 colors - 2.1+ pages - Square Pixels
  174.  
  175.     LastMode      = 17;      Number of modes
  176.  
  177.     RBackward     = 0;       Rotate Palette backward
  178.     RForward      = 1;       Rotate Palette forward
  179.     InvalidXMode  = -1;      The selected XMode doesn't exist (returned by
  180.                                                             xsetmode ).
  181.     Error         = 1;       Possible value for ErrorValue
  182.     AlignData     = 6;       Used by VBM routines
  183.     LeftPressed   = 1;       Possible value for MouseButtonStatus
  184.     RightPressed  = 2;       Possible value for MouseButtonStatus
  185.  
  186. Var
  187.     InGraphics,              - 1 if in a graphics mode, 0 otherwise
  188.     ErrorValue,              - Set by every routine to indicate success or
  189.                      failure
  190.     FontDriverActive,        - Set after a call to xtextinit
  191.     CharHeight,              - Height of the current character set
  192.     CharWidth,               - Width of the current character set
  193.     FirstChar,               - First character in character set
  194.     UserChHeight,            - Height of the User Font
  195.     UserChWidth,             - Width of the User Font
  196.     UserFirstCh,             - First character in User's font
  197.     DoubleScanFlag : Byte;   - 1 if mode is double-scanned, 0 otherwise
  198.     CurrXMode,               - Contains value of current graphics mode
  199.     ScrnPhysicalByteWidth,   - Physical width of the screen in bytes
  200.                      ( ie : group of 4 pixels )
  201.     ScrnPhysicalPixelWidth,  - Physical width of the screen in pixels
  202.     ScrnPhysicalHeight,      - Physical height of the screen in pixels
  203.     SplitScrnOffs,           - Offset in VRAM of Split Screen
  204.     SplitScrnScanLine,       - Screen Line where Split Screen is displayed
  205.     SplitScrnVisibleHeight,  - Height of the visible part of the split screen
  206.     SplitScrnActive,         - Contains 1 if SplitScreen is visible,0 otherwise
  207.     Page0Offs,               - Offset in VRAM of 1st page
  208.     Page1Offs,               - Offset in VRAM of 2nd page ( xsetdoublebuffer )
  209.     Page2Offs,               - Offset in VRAM of 3rd page ( xsettriplebuffer )
  210.     ScrnLogicalByteWidth,    - Width in bytes ( groups of 4 pixels ) of a page
  211.     ScrnLogicalPixelWidth,   - Width in pixels of a page
  212.     ScrnLogicalHeight,       - Height in pixels of a page
  213.     MaxScrollX,              - Maximum value for left edge of screen
  214.     MaxScrollY,              - Maximum value for top edge of screen
  215.     DoubleBufferActive,      - Set by xsetdoublebuffer
  216.     TripleBufferActive,      - Set by xsettriplebuffer
  217.     VisiblePageIdx,          - Number of the Visible Page
  218.     HiddenPageOffs,          - Offset of the Hidden page
  219.     VisiblePageOffs,         - Offset of the Visible page
  220.     WaitingPageOffs,         - Offset of the Waiting page
  221.     NonVisualOffs,           - Offset of start of unused VRAM
  222.     TopClip,                 - Top clipping edge
  223.     BottomClip,              - Bottom clipping edge
  224.     LeftClip,                - Left clipping edge
  225.     RightClip,               - Right clipping edge
  226.     PhysicalStartPixelX,     - X coordinate of top left pixel
  227.     PhysicalStartByteX,      - X coordinate of top left pixel /4
  228.     PhysicalStartY,          - Y coordinate of top left pixel
  229.     VsyncHandlerActive,      - set to 1 if the VSync handler has been installed
  230.     MouseInstalled,          - set to 1 if the Mouse handler has been installed
  231.     MouseHidden,             - set to 1 if after a call to xhidemouse
  232.     MouseButtonStatus,       - information on the button presses
  233.     MouseButtonCount,        - the number of buttons on the mouse
  234.     MouseX,                  - X coordinate of mouse pointer
  235.     MouseY,                  - Y coordinate of mouse pointer
  236.     MouseVersion : word;     - Version of Mouse driver
  237.     MouseFrozen,             - set to 1 if you want to update the mouse manually
  238.     MouseColor : byte;       - color of the mouse pointer
  239.  
  240. ╔═══════════════════════════════════════════════════════════════════════════╗
  241. ║ XLIB2 : EXPORTED PROCEDURES AND FUNCTIONS                                 ║
  242. ╚═══════════════════════════════════════════════════════════════════════════╝
  243.  
  244. ╔═══════════════════════════════════════════════════════════════════════════╗
  245. ║ GENERAL PROCEDURES AND FUNCTIONS                                          ║
  246. ╚═══════════════════════════════════════════════════════════════════════════╝
  247.  
  248.     Function  XSetMode( Mode, WidthInPixels : Word ) : Word;
  249.     --------------------------------------------------------
  250.  
  251.     Mode            - The required mode
  252.     WidthInPixels   - The width of the logical screen
  253.  
  254.     This function initialises the graphics system, setting the apropriate
  255.     screen resolution and allocating a virtual screen. The virtual screen
  256.     allocated may not necessarily be of the same size as specified in the
  257.     WidthInPixels parameter as it is rounded down to the nearest
  258.     multiple of 4.
  259.  
  260.     The function returns the actual width of the allocated virtual screen
  261.     in pixels if a valid mode was selected otherwise returns
  262.     XMODEINVALID.
  263.  
  264.     Saves virtual screen pixel width in ScrnLogicalPixelWidth.
  265.     Saves virtual screen byte  width in ScrnLogicalByteWidth.
  266.     Physical screen dimensions are set in ScrnPhysicalPixelWidth.
  267.     ScrnPhysicalByteWidth and ScrnPhysicalHeight. Other global variables
  268.     set are CurrXMode,MaxScrollX, MaxScrollY, InGraphics.
  269.     The variable SplitScrnScanline is also initialized to zero.
  270.  
  271.  
  272.     Procedure XSelectDefaultPlane( Plane : Byte );
  273.     ----------------------------------------------
  274.  
  275.     Enables default Read/Write access to a specified plane
  276.  
  277.  
  278.     Procedure XSetSplitscreen( Line : Word );
  279.     -----------------------------------------
  280.  
  281.         line            - The starting scan line of the required split screen.
  282.  
  283.     This function activates Mode X split screen and sets starting scan line
  284.     The split screen resides on the bottom half of the screen and has a
  285.     starting address of A000:0000 in video RAM.
  286.  
  287.     It also Updates Page0Offs to reflect the existence of the split screen
  288.     region ie MainScrnOffset is set to the offset of the first pixel
  289.     beyond the split screen region. Other variable set are Page1Offs which
  290.     is set to the same value as Page0Offs (see graphics call sequence below),
  291.     ScrnLogicalHeight,ScrnPhysicalHeight, SplitScrnScanLine and
  292.     MaxScrollY.
  293.  
  294.     This function cannot be called after double buffering has been activated,
  295.     it will return an error. To configure your graphics environment the
  296.     sequence of graphics calls is as follows although either or both steps b
  297.     and c may be omitted:
  298.         a) xsetmode
  299.         b) xsetsplitscreen
  300.         c) xsetdoublebuffer
  301.     Thus when you call this function successfully, double buffering is not
  302.     active so Page1Offs is set to the same address as Page0Offs.
  303.  
  304.     WARNING: If you use one of the high resolution modes (376x564 as an
  305.     extreme example) you may not have enough video ram for split screen
  306.     and double buffering options since VGA video RAM is restricted to 64K.
  307.  
  308.  
  309.     Procedure XSetStartAddr( X, Y : Word );
  310.     ---------------------------------------
  311.  
  312.     X,Y - coordinates of top left corner of physical screen within current
  313.     virtual screen.
  314.  
  315.     Set Mode X non split screen physical start address within current virtual
  316.     page.
  317.  
  318.     X must not exceed (Logical screen width - Physical screen width)
  319.     ie MaxScrollX and Y must not exceed (Logical screen height -
  320.     Physical screen height) ie MaxScrollY
  321.  
  322.  
  323.     Procedure XHideSplitscreen;
  324.     ---------------------------
  325.  
  326.     This function hides an existing split screen by setting its starting
  327.     scan line to the last physical screen scan line.
  328.     ScreenPhysicalHeight is adjusted but the SplitScreenScanLine is not
  329.     altered as it is required for restoring the split screen at a later stage.
  330.  
  331.     WARNING: Only to be used if SplitScrnLine has been previously called
  332.          The memory for  the initial split screen is reserved and the size
  333.          limitations of certain modes means any change in the split screen scan
  334.          line will encroach on the split screen ram.
  335.  
  336.     Procedure XShowSplitscreen;
  337.     ---------------------------
  338.  
  339.     Restores split screen start scan line to the initial split screen
  340.     starting scan line as set by SplitScrnScanLine.
  341.     ScreenPhysicalHeight is adjusted.
  342.  
  343.     WARNING: Only to be used if SplitScrnLine has been previously called
  344.          The memory for the initial split screen is reserved and the size
  345.          limitations of certain modes means any change in the split screen scan
  346.          line will encroach on the split screen ram.
  347.  
  348.     Procedure XAdjustSplitscreen( Line : Word );
  349.     --------------------------------------------
  350.  
  351.         line          - The scan line at which the split screen is to start.
  352.  
  353.     Sets the split screen start scan line to a new scan line. Valid scan lines
  354.     are between the initial split screen starting scan line and the last
  355.     physical screen scan line. ScreenPhysicalHeight is also adjusted.
  356.  
  357.     WARNING: Only to be used if SplitScrnLine has been previously called
  358.          The memory for the initial split screen is reserved and the size
  359.          limitations of certain modes means any change in the split screen scan
  360.          line will encroach on the split screen ram.
  361.  
  362.     Procedure XSetDoubleBuffer( PageHeight : Word );
  363.     ------------------------------------------------
  364.  
  365.         PageHeight    - The height of the two double buffering virtual screens.
  366.         Returns       - The closest possible height to the specified.
  367.  
  368.     This function sets up two double buffering virtual pages. ErrorValue
  369.     is set according to the success or failure of this command.
  370.  
  371.     Other variables set are:
  372.  
  373.         Page1Offs            -  Offset of second virtual page
  374.         NonVisualOffs        -  Offset of first non visible video ram byte
  375.         DoubleBufferActive   -  Flag
  376.         PageAddrTable        -  Table of Double buffering pages start offsets
  377.         ScrnLogicalHeight    -  Logical height of the double buffering pages
  378.         MaxScrollY           -  Max vertical start address of physical screen
  379.                                                         within the virtual screen
  380.  
  381.     WARNING: If you use one of the high resolution modes (376x564 as an
  382.          extreme example) you may not have enough video ram for split screen
  383.          and double buffering options since VGA video RAM is restricted to 
  384.          64K.
  385.  
  386.     Procedure XSetTripleBuffer( PageHeight : word );
  387.     ------------------------------------------------
  388.  
  389.     This procedure behaves like xdoublebuffer, but when used with
  390.     xinstallvsynchandler you can draw immediately after a page flip.
  391.     When xpageflip is called, VisiblePageOffs is set to the page that
  392.     will be display next vsync. Until then, WaitingPageOffs will be displayed.
  393.     You can draw to HiddenPageOffs .
  394.  
  395.     Procedure XPageFlip( X, Y : Word );
  396.     -----------------------------------
  397.  
  398.     X,Y - coordinates of top left corner of physical screen within the
  399.     the hidden virtual screen if double buffering is active, or
  400.     the current virtual screen otherwise.
  401.  
  402.     Sets the physical screen start address within currently hidden virtual
  403.     page and then flips pages. If double buffering is not active then this
  404.     function is functionally equivalent to xsetstartaddr.
  405.  
  406.     X must not exceed (Logical screen width - Physical screen width)
  407.     ie MaxScrollX and Y must not exceed (Logical screen height -
  408.     Physical screen height) ie MaxScrollY
  409.  
  410.     Procedure XSetClipRect( Left, Top, Right, Bottom : Word );
  411.     ----------------------------------------------------------
  412.  
  413.     Defines the clipping rectangle for clipping versions of planar and video
  414.     bitmap puts. Left and Right are in bytes (i.e. multiples of 4 pixels),
  415.     Top and Bottom are in pixels.
  416.     Thus the following call
  417.     
  418.     xsetcliprect(2,4,40,150);
  419.  
  420.     Would set the clipping rectangle to (8,4,160,150)
  421.  
  422.  
  423.     NOTE: Compiled bitmaps cannot be clipped.
  424.  
  425.     Procedure XTextMode;
  426.     --------------------
  427.  
  428.     Disables graphics mode.
  429.  
  430.     Procedure XWaitVsync;
  431.     ---------------------
  432.  
  433.     Waits for a vsync to occur : i.e. when the electron beam that's refreshing
  434.     the video image has reached the bottom of the screen.
  435.  
  436.  
  437. ╔═══════════════════════════════════════════════════════════════════════════╗
  438. ║ DRAWING PROCEDURES AND FUNCTIONS                                          ║
  439. ╚═══════════════════════════════════════════════════════════════════════════╝
  440.  
  441.     Procedure XLine( x1, y1, x2, y2, Color, PgOffs : word );
  442.     --------------------------------------------------------
  443.  
  444.     Draw a line with the specified end points in the page starting at
  445.     offset PageBase.
  446.  
  447.     No Clipping is performed.
  448.  
  449.  
  450.     Procedure XPutPix( X,Y,PgOfs,Color:word );
  451.     ------------------------------------------
  452.  
  453.     Draw a point of specified colour at coordinates X,Y within the virtual page
  454.     starting at offset PgOfs.
  455.  
  456.     Function  XGetPix( x,y,PageBase:word ) : word;
  457.     ----------------------------------------------
  458.  
  459.     Read a point of at coordinates X,Y within the virtual page starting
  460.     at offset PageOffset.
  461.  
  462.     Procedure XRectFill( StartX,StartY,EndX,EndY,PageBase,Color:word );
  463.     -------------------------------------------------------------------
  464.  
  465.         StartX,StartY - Coordinates of upper left hand corner of rectangle
  466.         EndX,EndY     - Coordinates of lower right hand corner of rectangle
  467.         PageBase      - Offset of virtual screen
  468.         Color         - Color of the box.
  469.  
  470.  
  471.     Mode X rectangle fill routine.
  472.  
  473.     Procedure XRectPattern( StartX,StartY,EndX,EndY,PageBase:word; var Pattern);
  474.     ----------------------------------------------------------------------------
  475.  
  476.         StartX,StartY - Coordinates of upper left hand corner of rectangle
  477.         EndX,EndY     - Coordinates of lower right hand corner of rectangle
  478.         PageBase      - Offset of virtual screen
  479.         Pattern       - Untyped variable for the user defined pattern (16 bytes)
  480.  
  481.  
  482.     Mode X rectangle 4x4 pattern fill routine.
  483.  
  484.     Upper left corner of pattern is always aligned to a multiple-of-4
  485.     row and column. Works on all VGAs. Uses approach of copying the
  486.     pattern to off-screen display memory, then loading the latches with
  487.     the pattern for each scan line and filling each scan line four
  488.     pixels at a time. Fills up to but not including the column at EndX
  489.     and the row at EndY. No clipping is performed.
  490.  
  491.     Warning the VGA memory locations PATTERNBUFFER (A000:FFFc) to
  492.     A000:FFFF are reserved for the pattern buffer
  493.  
  494.     Procedure XCpVidPage( SourceOffs, DestOffs : word );
  495.     ----------------------------------------------------
  496.  
  497.         SourceOffs    - Offset of source video page
  498.         DestOffs      - Offset of destination page
  499.  
  500.     Copies the contents of page SourceOffs to DestOffs. Twice as fast as a
  501.     xcpvidrect would be (because it uses less parameters, so less stack work is
  502.     required).
  503.  
  504.     Procedure XCpVidRect( SrcStartX,SrcStartY,SrcEndX,SrcEndY,DestStartX,
  505.         SourcePageBase,DestPageBase,SourceBitmapW,DestBitmapW:word );
  506.     ---------------------------------------------------------------------
  507.  
  508.         StartX,StartY - Coordinates of upper left hand corner of source rectangle
  509.         EndX,EndY     - Coordinates of lower right hand corner of source rectangle
  510.         DestStartX,DestStartY - Coordinates of rectangle destination
  511.         SourcePageBase        - source rectangle page offset
  512.         DestPageBase          - destination rectangles page offset
  513.         SourceBitmapWidth     - width of bitmap within the source virtual screen
  514.                     containing the source rectangle
  515.         DestBitmapWidth       - width of bitmap within the dest. virtual screen
  516.                     containing the destination rectangle
  517.  
  518.     Mode X display memory to display memory copy
  519.     routine. Left edge of source rectangle modulo 4 must equal left edge
  520.     of destination rectangle modulo 4. Works on all VGAs. Uses approach
  521.     of reading 4 pixels at a time from the source into the latches, then
  522.     writing the latches to the destination. Copies up to but not
  523.     including the column at SrcEndX and the row at SrcEndY. No
  524.     clipping is performed. Results are not guaranteed if the source and
  525.     destination overlap.
  526.  
  527.     Procedure XShiftRect( SrcLeft,SrcTop,SrcRight,SrcBottom,DestLeft,DestTop,
  528.             ScreenOffs:word );
  529.     -------------------------------------------------------------------------
  530.  
  531.     SrcLeft, SrcTop - Coordinates of upper left hand corner of rectangle
  532.     SrcRight, SrcBottom - Coordinates of lower right hand corner of rectangle
  533.     DestLeft, DestTop - Coordinates of upper left corner of destination
  534.     ScreenOffs    - Offset of virtual screen
  535.  
  536.     This function copies a rectangle of VRAM onto another area of VRAM,
  537.     even if the destination overlaps with the source.  It is designed
  538.     for scrolling text up and down, and for moving large areas of screens
  539.     around in tiling systems.  It rounds all horizontal coordinates to
  540.     the nearest byte (4-column chunk) for the sake of speed.  This means
  541.     that it can NOT perform smooth horizontal scrolling.  For that,
  542.     either scroll the whole screen (minus the split screen), or copy
  543.     smaller areas through system memory using the functions in the
  544.     XBM2 module.
  545.  
  546.     SrcRight is rounded up, and the left edges are rounded down, to
  547.     ensure that the pixels pointed to by the arguments are inside the
  548.     the rectangle.  That is, SrcRight is treated as (SrcRight+3) >> 2,
  549.     and SrcLeft as SrcLeft >> 2.
  550.  
  551.     The width of the rectangle in bytes (width in pixels / 4)
  552.     cannot exceed 255.
  553.  
  554.     Procedure XCircle( Left, Top, Diameter, Color, ScreenOffs:word );
  555.     -----------------------------------------------------------------
  556.  
  557.     Draws a circle with the given upper-left-hand corner and diameter,
  558.     which are given in pixels.
  559.  
  560.     Procedure XFilledCircle( Left, Top, Diameter, Color, ScreenOffs:word );
  561.     -----------------------------------------------------------------------
  562.  
  563.     Draws a filled circle with the given upper-left-hand corner and
  564.     diameter.
  565.  
  566.     xtriangle
  567.     ---------
  568.  
  569.     procedure xtriangle( x0, y0, x1, y1, x2, y2 : integer;
  570.         color, PageBase : word );
  571.  
  572.     This function draws a filled triangle which is clipped to the current
  573.     clipping window defined by TopClip,BottomClip,LeftClip,RightClip.
  574.     Remember: the X clipping variable are in byteS not PIXELS so you can only
  575.     clip to 4 pixel byte boundaries.
  576.  
  577.  
  578.     xpolygon
  579.     --------
  580.  
  581.     procedure xpolygon( var vertices; numvertices : integer;
  582.         color, PageBase : word );
  583.  
  584.     This function is similar to the triangle function but draws
  585.     convex polygons. The vertices are supplied as an array of vertices.
  586.  
  587.     NOTE: a convex polygon is one such that if you draw a line from
  588.     any two vertices, every point on that line will be within the
  589.     polygon.
  590.  
  591.     This function works by splitting up a polygon into its component
  592.     triangles and calling the triangle routine above to draw each one.
  593.     Performance is respectable but a custom polygon routine might be
  594.     faster.
  595.  
  596.  
  597.     xfloodfill
  598.     ----------
  599.  
  600.     Function xfloodfill(int x, int y, unsigned ofs, int color) : integer;
  601.  
  602.     This function performs the familiar flood filling used by many
  603.     paint programs and of course the Borland BGI's flood fill function.
  604.     The pixel at x,y and all adjacent pixels of the same color are filled
  605.     to the new color. Filling stops when there are no more adjacent pixels
  606.     of the original pixel's color. The function returns the number of
  607.     pixels that have been filled.
  608.  
  609.     xboundaryfill
  610.     -------------
  611.  
  612.     Function xboundaryfill( x, y, ofs, boundary, color : integer ) : integer;
  613.  
  614.     This function is a variant of the flood fill described above. This
  615.     function, unlike the above function, can fill across color boundaries.
  616.     Filling stops when the area being filled is fully enclosed by pixels
  617.     of the color boundary. Again, this function returns the number of
  618.     pixels filled.
  619.  
  620. ╔═══════════════════════════════════════════════════════════════════════════╗
  621. ║ PALETTE PROCEDURES AND FUNCTIONS                                          ║
  622. ╚═══════════════════════════════════════════════════════════════════════════╝
  623.  
  624.     There are two sets of procedures in function that deal with changing the
  625.     palette : the Struc and the Raw ones. The Struc procs work with what is also
  626.     referred to as an annotated buffer which contains the first colour and the
  627.     number of colours stored apart from the DAC data. Raw buffers just contain
  628.     the DAC data.
  629.  
  630.  
  631.     Procedure XGetPalStruc( var PalBuff; NumColors,StartColor:word );
  632.     -----------------------------------------------------------------
  633.  
  634.     Read DAC palette into annotated type buffer with interrupts disabled
  635.     ie byte colours to skip, byte colours to set, r1,g1,b1,r1,g2,b2...rn,gn,bn
  636.  
  637.     WARNING: memory for the palette buffers must all be pre-allocated
  638.  
  639.     Procedure XGetPalRaw( Var PalBuff; NumColors,StartColor:word );
  640.     ---------------------------------------------------------------
  641.  
  642.     Read DAC palette into raw buffer with interrupts disabled
  643.     ie byte r1,g1,b1,r1,g2,b2...rn,gn,bn
  644.  
  645.     WARNING: Memory for the palette buffers must all be pre-allocated.
  646.  
  647.     Procedure XPutPalStruc( Var CompPalBuff );
  648.     ------------------------------------------
  649.  
  650.     Write DAC palette from annotated type buffer with interrupts disabled
  651.     ie byte colours to skip, byte colours to set, r1,g1,b1,r1,g2,b2...rn,gn,bn
  652.  
  653.     Procedure XTransposePalStruc( Var CompPalBuff; StartColor:word );
  654.     -----------------------------------------------------------------
  655.  
  656.     Write DAC palette from annotated type buffer with interrupts disabled
  657.     starting at a new palette index.
  658.  
  659.     Procedure XPutPalRaw( Var PalBuff; NumColors,StartColor:word );
  660.     ---------------------------------------------------------------
  661.  
  662.     Write DAC palette from raw buffer with interrupts disabled
  663.     ie byte r1,g1,b1,r1,g2,b2...rn,gn,bn
  664.  
  665.     Procedure XSetRGB( ColorIndex,R,G,B:byte );
  666.     -------------------------------------------
  667.  
  668.     Set the RGB components of a vga color
  669.  
  670.     Procedure XRotPalStruc( Var PalBuff; Direction:word );
  671.     ------------------------------------------------------
  672.  
  673.     Rotate annotated palette buffer entries. Direction 0 = backward,
  674.     1 = forward.
  675.  
  676.     Procedure XRotPalRaw( Var PalBuff; Direction, NumColors:word );
  677.     ---------------------------------------------------------------
  678.  
  679.     Rotate a raw palette buffer. Direction 0 = backward,
  680.     1 = forward.
  681.  
  682.     Function  XCpContrastPalStruc( Var PalSrcBuff,PalDestBuff; Intensity:byte ) : word;
  683.     -----------------------------------------------------------------------------------
  684.  
  685.     Copy one annotated palette buffer to another making the intensity
  686.     adjustment. Used in fading in and out fast and smoothly.
  687.  
  688.     Procedure XPutContrastPalStruc( Var CompPalBuff; Intensity:byte );
  689.     ------------------------------------------------------------------
  690.  
  691.     Write DAC palette from annotated type buffer with specified intensity
  692.     adjustment (ie palette entries are decremented where possible by
  693.     intensity units).
  694.  
  695.     Designed for fading in or out a palette without using an intermediate
  696.     working palette buffer ! (Slow but memory efficient ... OK for small
  697.     pal strucs)
  698.  
  699. ╔═══════════════════════════════════════════════════════════════════════════╗
  700. ║ TEXT PROCEDURES AND FUNCTIONS                                             ║
  701. ╚═══════════════════════════════════════════════════════════════════════════╝
  702.  
  703.     Note : the fonts supplied with XLIB2 come mostly from Kai Rohrbacher's ANIVGA
  704.     package.
  705.  
  706.     Function  XCharPut( Chr:char; X, Y, ScrnOffs, Color:word ) : byte;
  707.     ------------------------------------------------------------------
  708.  
  709.     Draw a text character at the specified location with the specified
  710.     color.
  711.  
  712.         ch       -  char to draw
  713.         x,y      -  screen coords at which to draw ch
  714.         ScrnOffs -  Starting offset of page on whih to draw
  715.         Color    -  Color of the text
  716.  
  717.     WARNING: xtextinit must be called before using this function
  718.  
  719.  
  720.     Procedure XSetFont( FontID : word );
  721.     ------------------------------------
  722.  
  723.     Procedure xsetfont(FontId : word);
  724.  
  725.     Select the working font where 0 = VGA ROM 8x8, 1 = VGA ROM 8x14
  726.     2 = User defined bitmapped font.
  727.  
  728.     WARNING: A user font must be registered before setting FontID 2
  729.  
  730.     Procedure XTextInit;
  731.     --------------------
  732.  
  733.     Initializes the Mode X text driver and sets the default font (VGA ROM 8x8)
  734.  
  735.     Procedure XRegisterUserFont( var FontToRegister );
  736.     --------------------------------------------------
  737.  
  738.     Register a user font for later selection. Only one user font can be
  739.     registered at any given time. Registering a user font deregisters the
  740.     previous user font. User fonts may be at most 8 pixels wide.
  741.  
  742.     USER FONT STRUCTURE
  743.  
  744.     Word:  ascii code of first char in font
  745.     Byte:  Height of chars in font
  746.     Byte:  Width of chars in font
  747.     n*h*Byte: the font data where n = number of chars and h = height
  748.         of chars
  749.  
  750.     WARNING: The onus is on the program to ensure that all characters
  751.          drawn whilst this font is active, are within the range of
  752.          characters defined.
  753.  
  754.     Function  XGetCharWidth( ch : char ) : byte;
  755.     --------------------------------------------
  756.  
  757.     Returns the width in pixels of character ch in the currently selected font.
  758.  
  759.  
  760.     Function  XPrintf( x, y, ScrnOffs, Color : word; s : string ) : integer;
  761.     ------------------------------------------------------------------------
  762.  
  763.         x,y      -  screen coords at which to draw ch
  764.         ScrnOffs -  Starting offset of page on whih to draw
  765.         Color    -  Color of the text
  766.         s        -  The string to be displayed
  767.  
  768.     Displays the string s at coordinates x,y on page ScrnOffs in Color.
  769.     Returns the width of the string in pixels.
  770.  
  771.  
  772.     Procedure XBgPrintf( x, y, ScrnOffs, fgcolor, bgcolor : word; s : string );
  773.     ---------------------------------------------------------------------------
  774.  
  775.         x,y      -  screen coords at which to draw ch
  776.         ScrnOffs -  Starting offset of page on whih to draw
  777.         fgcolor  -  Color of the text foreground
  778.         bgcolor  -  Color of the text background
  779.         s        -  The string to be displayed
  780.  
  781.     Same as XPrintf but erases the background of the string with color bgcolor.
  782.  
  783. ╔═══════════════════════════════════════════════════════════════════════════╗
  784. ║ MOUSE PROCEDURES AND FUNCTIONS                                            ║
  785. ╚═══════════════════════════════════════════════════════════════════════════╝
  786.  
  787.  
  788.     Procedure XDefineMouseCursor( var MouseDef; MouseColor:byte );
  789.     --------------------------------------------------------------
  790.  
  791.     MouseDef - a buffer of 14 characters containing a bitmask for all the
  792.              cursor's rows.
  793.     MouseColor - The colour to use when drawing the mouse cursor.
  794.  
  795.     Define a mouse cursor shape for use in subsequent cursor redraws. XMouse
  796.     has a hardwired mouse cursor size of 8 pixels across by 14 pixels down.
  797.  
  798.     WARNING: This function assumes MouseDef points to 14 bytes.
  799.  
  800.     Note: Bit order is in reverse. ie bit 7 represents pixel 0 ..
  801.         bit 0 represents pixel 7 in each MouseDef byte.
  802.  
  803.     procedure XMouseInit;
  804.     ---------------------
  805.  
  806.     Initialize the mouse driver functions and install the mouse event handler
  807.     function. This is the first function you must call before using any of the
  808.     mouse functions. This mouse code uses the fastest possible techniques to
  809.     save and restore mouse backgrounds and to draw the mouse cursor.
  810.  
  811.     WARNING: This function uses and updates NonVisualOffset to allocate
  812.          video ram for the saved mouse background.
  813.  
  814.     LIMITATIONS: No clipping is supported horizontally for the mouse cursor
  815.                  No validity checking is performed for NonVisualOffs
  816.  
  817.     **WARNING** You must Hide or at least Freeze the mouse cursor while drawing
  818.     using any of the other XLIB procedures since the mouse handler may
  819.     modify vga register settings at any time. VGA register settings
  820.     are not preserved which will result in unpredictable drawing behavior.
  821.     If you know the drawing will occur away from the mouse cursor set
  822.     MouseFrozen to 1, do your drawing  then set it to 0.
  823.     Alternatively call xhidemouse, perform your drawing and then call
  824.     xshowmouse. Another alternative is to disable interrupts while drawing
  825.     but usually drawing takes up alot of time and having interrupts
  826.     disabled for too long is not a good idea.
  827.     If you are using the Virtual VSync Handler and just updating the palette 
  828.     you don't need to freeze the mouse.
  829.  
  830.     Procedure XMouseWindow( x0, y0, x1, y1:word );
  831.     ----------------------------------------------
  832.  
  833.     Defines a mouse window. The mouse can't move outside the boundaries
  834.     specified.
  835.  
  836.     procedure XShowMouse;
  837.     ---------------------
  838.  
  839.     Makes the cursor visible if it was previously hidden.
  840.  
  841.     Procedure XHideMouse;
  842.     ---------------------
  843.  
  844.     Makes the cursor hidden if it was previously visible.
  845.  
  846.     Procedure XMouseRemove;
  847.     -----------------------
  848.  
  849.     Stop mouse event handling and remove the mouse handler.
  850.  
  851.     NOTE: This function MUST be called before quitting the program if
  852.     a mouse handler has been installed
  853.  
  854.     Procedure XPositionMouse( X, Y : word );
  855.     ----------------------------------------
  856.  
  857.     Positions the mouse at a specified location
  858.  
  859.     Procedure XUpdateMouse;
  860.     -----------------------
  861.  
  862.     Forces the mouse position to be updated and cursor to be redrawn.
  863.     Note: this function is useful when you have set MouseFrozen to true.
  864.     Allows the cursor position to be updated manually rather than
  865.     automatically by the installed handler.
  866.  
  867. ╔═══════════════════════════════════════════════════════════════════════════╗
  868. ║ VSYNC HANDLER PROCEDURES AND FUNCTIONS                                    ║
  869. ╚═══════════════════════════════════════════════════════════════════════════╝
  870.  
  871.     The xvsync module uses timer 0 to simulate a vertical retrace interrupt.
  872.     It's designed to significantly reduce the idle waiting time in Xlib.
  873.     Why simulate the VRT interrupt ? Simply because a true VRT interrupt is
  874.     not implemented on many VGA cards. Using a VRT interrupt as opposed to
  875.     polling, can result in huge performance improvements for your code and
  876.     help make animation much smoother than it would be using polling.
  877.  
  878.     Normally xlib waits for vsync when xpageflip, xsetstartaddress or
  879.     xputpal??? is called. This waiting period could be better utilized to do
  880.     housekeeping calculations or whatever. The xputpal??? functions also
  881.     doesn't work very smoothly in conjunction with other functions that wait for
  882.     the vertical retrace since each function introduces its own VRT delay.
  883.  
  884.     When using the vsync handler, the VRT delay is reduced to the absolute
  885.     minumum which can result in a huge performance boost for your programs.
  886.     
  887.     When using double buffering, you may still have to wait before drawing,
  888.     but you could do as much other work as possible, like this:
  889.  
  890.         xpageflip(...)
  891.         ...
  892.         <animate the palette>
  893.         <do some collision detection and 3D calculations>
  894.         <read the joystick>
  895.         ...
  896.         <draw next frame>
  897.         ...
  898.  
  899.  
  900.         Procedure XInstallVSyncHandler( VrtsToSkip : word );
  901.         ----------------------------------------------------
  902.  
  903.         This function installs the vsync handler using timer 0. It's called
  904.         about 100 microseconds before every vertical retrace.
  905.  
  906.         The VrtsToSkip value (>=1) defines the delay in VRT's between consecutive
  907.         physical screen start address changes, thus allowing you to limit the
  908.         maximum frame rate for page flips in animation systems. The frame rate
  909.         is calculated as Vertical refresh rate / VrtsToSkip, eg for
  910.         320x240 mode which refreshes at 60Hz a VrtsToSkip value of 3 will result
  911.         in a maximum page flipping rate of 20Hz (frames per second)
  912.  
  913.         WARNING:  Be sure to remove it before exiting.
  914.                 When used with a debugger, the system clock may speed up.
  915.  
  916.     Procedure XRemoveVSyncHandler;
  917.     ------------------------------
  918.  
  919.     This routine MUST be called before exiting (or aborting) the program,
  920.     or your system will crash.
  921.  
  922.     Procedure XSetUserVSyncHandler( handler : pointer );
  923.     ---------------------------------------------------
  924.  
  925.     Installs a user routine to be called once each vertical retrace. The user
  926.     handler has its own stack of 256 bytes.
  927.     WARNING: This installs an interrupt driven handler, beware of the following:
  928.          Only 8086 registers are preserved. If you're using 386 code, save
  929.          all the 386 regs.
  930.          Don't do any drawing.
  931.          Don't call any DOS functions.
  932.  
  933.     So why use it?
  934.     Well, you can update global variables if you're careful. And it's nice for
  935.     palette animation. You can even do fades while loading from disk. You
  936.     should use this instead of installing your own int08h routine and chain
  937.     to the original.
  938.